package com.huike.web.controller.activity;

import com.huike.clues.domain.Activity;
import com.huike.clues.domain.dto.ActivityDTO;
import com.huike.clues.service.ActivityService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("clues/activity")
@Slf4j
public class ActivityController extends BaseController {
    @Autowired
    private ActivityService activityService;
    @GetMapping("/list")
    /**
     *  查询活动信息列表
     */
    public TableDataInfo pageQuery(ActivityDTO activityDTO){
        startPage();
        List<Activity> activities = activityService.pageQuery(activityDTO);
        TableDataInfo dataTable = getDataTable(activities);
        log.info("返回的分页数据：{}",dataTable);
        return dataTable;
    }

    /**
     * 添加活动
     */
    @PostMapping("")
    public AjaxResult addActivity(@RequestBody Activity activity){
        int rows = activityService.addActivity(activity);
        return AjaxResult.success(rows);
    }

    /**
     * 根据渠道来源查询活动信息
     */
    @GetMapping("/listselect/{channel}")
    public AjaxResult selectByChannel(@PathVariable Long channel){
        List<Activity> activityList= activityService.selectByChannel(channel);
        return AjaxResult.success(activityList);
    }

    /**
     * 根据id查询活动信息
     */
    @GetMapping("{id}")
    public AjaxResult activity(@PathVariable Long id){
        Activity activity = activityService.selectById(id);
        return AjaxResult.success(activity);
    }

    /**
     * 更新
     * @param activity
     * @return
     */
    @PutMapping()
    public AjaxResult updateActivity(@RequestBody Activity activity){
        int rows = activityService.updateActivity(activity);
        return AjaxResult.success(rows);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("{ids}")
    public AjaxResult batchDelete(@PathVariable List ids){
        int rows  = activityService.batchDelete(ids);
        return AjaxResult.success(rows);
    }
}
